using System;
using System.Collections.Generic;
using System.Text;
using Entity;
using log4net;
using ECommerce.Library;
using System.Web;
using ECommerce.Library.Web;
using ECommerce.DAL;

namespace AutoGear.BLL
{
    public class UserFactory
    {
        public static SiteUser BuildSiteUser(string userName, string password)
        {
            CustomCollection<TblUser> tblUser = TblUserExtended.GetUserByUserName(userName);
            CustomCollection<TblUserRole> tblUserRole = TblUserRole.GetTblUserRoleByUserId(tblUser[0].UserId);
            CustomCollection<TblUserProfile> tblUserProfile = TblUserProfile.GetTblUserProfileByUserId(tblUser[0].UserId);
            string strUserRoleName = tblUserRole[0].RoleName;
            SiteUser siteUser;

            if (strUserRoleName == UserRoleType.AdminUser.ToString())
            {                
                AdminUser adminUser = new AdminUser(tblUser[0]);
                siteUser = adminUser as SiteUser;
            }
            else if (strUserRoleName == UserRoleType.CustomerAdmin.ToString())
            {                
                CustomerAdmin customerAdmin = new CustomerAdmin(tblUser[0], tblUserProfile[0]);
                siteUser = customerAdmin as SiteUser;
            }
            else if (strUserRoleName == UserRoleType.CustomerUser.ToString())
            {
                CustomerUser customerUser = new CustomerUser(tblUser[0], tblUserProfile[0]);
                siteUser = customerUser as SiteUser;
            }
            else 
            {
                SuperAdminUser superAdminUser = new SuperAdminUser(tblUser[0], tblUserProfile[0]);
                siteUser = superAdminUser as SiteUser;
            }
            return siteUser;
        }
    }
}
